package org.example

import scala.io.Source
object PalindromeChecker {
  def main(args: Array[String]):Unit
  ={
    //文件路径
    val filename = "D:\\spark/word.txt"
    //读取文件内容
  val fileContent = Source.fromFile(filename).mkString
    //将内容拆分为单词
  val words = fileContent.replaceAll("[^a-zA-Z\\s]","").toLowerCase.split("\\s+")
  //判断每一个单词是否为回文单词
    words.foreach { word =>
    if (isPalindrome(word)) {
     println(word)
    }
  }
  }
  //判断一个单词是否为回文单词
def isPalindrome(word: String):
Boolean = {
  word==word.reverse
}
}
